package com.chb.system.controller;

import com.chb.system.annotation.OperLogAnnotation;
import com.chb.system.service.RoleService;
import com.chb.system.service.RoleUserService;
import com.hos.entity.sys.Role;
import com.hos.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author ：张家琪
 * @date ：Created in 2023/12/21 9:54
 * @description：
 * @modified By：
 * @version:
 */
@RestController
@RequestMapping("system/role")
public class RoleConteoller {
    @Resource
    private RoleService roleService;
    @Resource
    private RoleUserService roleUserService;
    @Autowired
    private RedisTemplate redisTemplate;

    @GetMapping("/findRolesByUserId/{userId}")
    public List<Role> findRolesByUserId(@PathVariable Long userId) {
        return roleService.findRolesByUserId(userId);
    }

    // 保存用户和角色信息
    @PostMapping("/saveRoleUser/{userId}")
    @OperLogAnnotation(business_type = "系统业务-分配角色", operator_type = 1)
    public Result<Integer> saveRoleUser(@PathVariable Long userId, @RequestBody List<Long> roleIds) {
        // redisTemplate.delete("menu:leftMenu");
        return new Result<>(200, "分配成功", roleUserService.saveRoleUser(userId, roleIds));
    }
}